package com.app.shop.demo.activitys;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.shop.demo.MyApplication;
import com.app.shop.demo.R;
import com.app.shop.demo.adapters.OrderListAdapter;
import com.app.shop.demo.beans.OrderBean;
import com.app.shop.mylibrary.base.BaseActivity;
import com.app.shop.mylibrary.widgts.ScrollListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class   OrderListActivity extends BaseActivity {

    @BindView(R.id.lv)
    ScrollListView lv;
    @BindView(R.id.rela_empty)
    RelativeLayout relaEmpty;

    OrderListAdapter adapter;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_list);
        ButterKnife.bind(this);
        tvTitle.setText("订单列表");
        initView();
    }

    private void initView() {

        List<OrderBean> list = new ArrayList();
        if (MyApplication.orderList != null) {
            list.addAll(MyApplication.orderList);
        }

        if (list.size() > 0) {
            adapter = new OrderListAdapter(this, (ArrayList) list, R.layout.item_order_list);
            lv.setAdapter(adapter);
            lv.setVisibility(View.VISIBLE);
            relaEmpty.setVisibility(View.GONE);
        } else {
            lv.setVisibility(View.GONE);
            relaEmpty.setVisibility(View.VISIBLE);
        }


        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //进入订单详情
                Bundle bundle = new Bundle();
                bundle.putSerializable("orderBean", list.get(position));
                showActivity(OrderListActivity.this, OrderDetailActivity.class, bundle);
            }
        });
    }

    @OnClick(R.id.imgv_return)
    public void onViewClicked() {
        onBackPressed();
    }

}
